package com.lq.controller;

import com.lq.pojo.Comment;
import com.lq.service.CommentService;
import com.lq.util.SystemLogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.List;

@Controller
public class CommentController {

    @Autowired
    private CommentService commentService;

    @RequestMapping("/deleteComment")
    public String deleteComment(String cId) {

        int commentId = Integer.parseInt(cId);

        commentService.deleteCommentByCommentId(commentId);

        SystemLogUtil.deleteCommentLog();

        return "forward://getAllComment";
    }

    @RequestMapping("/getAllComment")
    public String getAllComment(Model model) throws ServletException, IOException {

        List<Comment> commentList = commentService.getAllComment(10);

        model.addAttribute("commentList", commentList);

        return "comment";
    }

    @RequestMapping("/getLatestComment")
    public String getLatestComment(Model model) {
        List<Comment> latestCommentList = commentService.getLatestComment(5);

        model.addAttribute("latestCommentList", latestCommentList);

        return "panel";
    }


}
